﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace AutoLoL.Converters
{
    public class MasteryBuildToIntConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return 0;

            string masteryBuild = value.ToString();

            if (string.IsNullOrEmpty(masteryBuild))
                return 0;

            int start = 0;
            int length = masteryBuild.Length;

            if (parameter != null)
            {
                string[] parameters = parameter.ToString().Split(',');

                if (parameters.Length == 2)
                {
                    start = int.Parse(parameters[0]);
                    length = int.Parse(parameters[1]);
                }
            }


            int result = 0;
            for (int i = start; i < start + length; i++)
            {
                result += (int)Char.GetNumericValue(masteryBuild[i]);
            }

            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
